home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
pascal
/
spoc88.zip
/
FACTRL.ZIP
/
FACTORL.C
< prev
Wrap
Text File
|
1988-06-22
|
545b
|
31 lines
/* FACTORL.C: Computes factorial of a keyed number */
/* Repeats until user enters 0 */
#include <stdio.h>
main ()
{
int value, atoi();
long fact();
char input [6];
do {
printf ("\nValue? ");
gets (input);
value = atoi (input);
if (value > 0)
printf ("\nFactorial = %ld\n", fact (value));
else
puts ("\nCannot take factorial of negative number\n");
} while (value);
}
long fact (int val)
{
long result = 0;
if (val)
result = val * fact (val-1);
return (result);
}